﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrokerBase.Lib.Product;
using BrokerBase.Lib.Policy;

namespace broker.duty.PA
{
    public class ProductExpander : AbstractProductExpander
    {
        /// <summary>
        /// 保单加载完成
        /// </summary>
        /// <param name="policy"></param>
        public override void Loaded(IPolicy policy)
        {
            
            int basicPayLength = policy.Owner.BasicPolicy.PaymentPeriodLength;

            IPaymentPeriod prepp = null;

            foreach (IPaymentPeriod pp in policy.Product.PaymentPeriods)
            {
                
                if (pp.Value == basicPayLength)
                {
                    policy.SelectedPaymentPeriod = pp;
                    break;
                }
                else if (pp.Value > basicPayLength)
                {
                    policy.SelectedPaymentPeriod = prepp;
                    break;
                }
                prepp = pp;
            }

            policy.Amount = policy.Owner.Policies.Sum(p => p.Amount);


        }
    }
}
